# -*- coding: utf-8 -*-
# author: sixmillions
# date: 2022/04/11

"""
过滤列表,获取符合条件的数据
"""
from random import randint

data = [randint(-10, 10) for _ in range(0, 10)]
print(1, data)

# 推导式
res1 = [x for x in data if x >= 0]
print(2, res1)

# lambada
res2 = filter(lambda x: x >= 0, data)
print(3, list(res2))


# 如果处理复杂可以定义一个函数
def data_handler(item):
    # print("元素：", item)
    return item >= 0


res3 = filter(lambda x: data_handler(x), data)
print(4, list(res3))

# 循环（最low）
res4 = []
for x in data:
    if x >= 0:
        res4.append(x)
print(5, res4)
